home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DOS.SWG / 0015_Demostrates EXEC Proc.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-17  |  2KB  |  97 lines

  1. {$M 8192,0,0}
  2. {* This memory directive is used to make
  3.    certain there is enough memory left
  4.    to execute the DOS shell and any
  5.    other programs needed.  *}
  6.  
  7. Program EXEC_Demo;
  8.  
  9. {*
  10.  
  11.   EXEC.PAS
  12.  
  13.   This program demonstrates the use of
  14.   Pascal's EXEC function to execute
  15.   either an individual DOS command or
  16.   to move into a DOS Shell.
  17.  
  18.   You may enter any command you could
  19.   normally enter at a DOS prompt and
  20.   it will execute.  You may also hit
  21.   RETURN without entering anything and
  22.   you will enter into a DOS Shell, from
  23.   which you can exit by typing EXIT.
  24.  
  25.   The program stops when you hit a
  26.   'Q', upper or lower case.
  27. *}
  28.  
  29.  
  30. Uses Crt, Dos;
  31.  
  32. Var
  33.   Command : String;
  34.  
  35. {**************************************}
  36. Procedure Do_Exec; {*******************}
  37.  
  38.   Var
  39.     Ch : Char;
  40.  
  41.   Begin
  42.     If Command <> '' Then
  43.       Command := '/C' + Command
  44.     Else
  45.       Writeln('Type EXIT to return from the DOS Shell.');
  46.     {* The /C prefix is needed to
  47.        execute any command other than
  48.        the complete DOS Shell. *}
  49.  
  50.     SwapVectors;
  51.     Exec(GetEnv('COMSPEC'), Command);
  52.     {* GetEnv is used to read COMSPEC
  53.        from the DOS environment so the
  54.        program knows the correct path
  55.        to COMMAND.COM. *}
  56.  
  57.     SwapVectors;
  58.     Writeln;
  59.     Writeln('DOS Error = ',DosError);
  60.     If DosError <> 0 Then
  61.       Writeln('Could not execute COMMAND.COM');
  62.     {* We're assuming that the only
  63.        reason DosError would be something
  64.        other than 0 is if it couldn't
  65.        find the COMMAND.COM, but there
  66.        are other errors that can occur,
  67.        we just haven't provided for them
  68.        here. *}
  69.  
  70.     Writeln;
  71.     Writeln;
  72.     Writeln('Hit any key to continue...');
  73.     Ch := ReadKey;
  74.   End;
  75.  
  76.  
  77. Function Get_Command : String;
  78.  
  79.   Var
  80.     Count : Integer;
  81.     Cmnd : String;
  82.  
  83.   Begin
  84.     Clrscr;
  85.     Write('Enter DOS Command (or Q to Quit): ');
  86.     Readln(Cmnd);
  87.     Get_Command := Cmnd
  88.   End;
  89.  
  90. Begin
  91.   Command := Get_Command;
  92.   While NOT ((Command = 'Q') OR (Command = 'q')) Do
  93.     Begin
  94.       Do_Exec;
  95.       Command := Get_Command
  96.     End;
  97. End.